package com.example.subscriber.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @project: smart-property
 * @description: 手机验证码
 * @author: cjq
 * @create: 2022-11-24 09:25
 **/
@Configuration
public class SendPhoneMessagesConfig {
    public static final String CJQ_SEND_PHONE_MESSAGE_EXCHANGE_NAME = "cjq.send.phone.message.exchange.name";
    public static final String CJQ_SEND_PHONE_MESSAGE_QUEUE_NAME = "cjq.send.phone.message.queue.name";
    public static final String CJQ_SEND_PHONE_MESSAGE_ROUTING_KEY_NAME = "cjq.send.phone.message.routing.key.name";

    @Bean
    DirectExchange sendPhoneExchanges(){
        return new DirectExchange(CJQ_SEND_PHONE_MESSAGE_EXCHANGE_NAME);
    }

    //配置队列
    @Bean
    Queue sendPhoneMessagesQueue() {
        return new Queue(CJQ_SEND_PHONE_MESSAGE_QUEUE_NAME);
    }

    //绑定队列到交换机
    @Bean
    Binding sendMessagesBinding() {
        return BindingBuilder.bind(sendPhoneMessagesQueue()).to(sendPhoneExchanges()).with(CJQ_SEND_PHONE_MESSAGE_ROUTING_KEY_NAME);
    }
}
